define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'air/charter/index' + location.search,
                    add_url: 'air/charter/add',
                    edit_url: 'air/charter/edit',
                    // del_url: 'air/charter/del',
                    multi_url: 'air/charter/multi',
                    import_url: 'air/charter/import',
                    table: 'air_charter',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'plan_name', title: __('Plan_name'), operate: 'LIKE'},
                        {field: 'plan_name_ne', title: __('Plan_name_ne'), operate: 'LIKE'},
                        {field: 'order_status', title: __('预定状态'), searchList: {"0":__('未预定'),"1":__('已预定')}, formatter: Table.api.formatter.status,custom: {'1':'info', '0':'gray'}},
                        {field: 'sit_total', title: __('Sit_total')},
                        /*
                        {field: 'start_area_id', title: __('Start_area_id')},
                        {field: 'end_area_id', title: __('End_area_id')},
                        */
                        {field: 'flight_time', title: __('Flight_time'), operate:false},
                        {field: 'start_date', title: __('Start_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end_date', title: __('End_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'banner_image', title: __('Banner_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'price', title: __('Price')},
                        {field: 'underline_price', title: __('Underline_price')},
                        // {field: 'cabin_image', title: __('Cabin_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('显示状态'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            var startCityType = $('#c-start_city_type').val()
            if(startCityType=="in"){
                $('#in_start_city').show();
                $('#out_start_city').hide();
            }else{
                $('#in_start_city').hide();
                $('#out_start_city').show();
            }
            $(document).on("click", "input[type=radio][name='row[starttype]']",
              function(){
                if($(this).val()=="in"){
                    $('#in_start_city').show();
                    $('#out_start_city').hide();
                }else{
                    $('#in_start_city').hide();
                    $('#out_start_city').show();
                }
            })
            var endCityType = $('#c-end_city_type').val()
            if(endCityType=="in"){
                $('#in_end_city').show();
                $('#out_end_city').hide();
            }else{
                $('#in_end_city').hide();
                $('#out_end_city').show();
            }
            $(document).on("click", "input[type=radio][name='row[endtype]']",
              function(){
                if($(this).val()=="in"){
                    $('#in_end_city').show();
                    $('#out_end_city').hide();
                }else{
                    $('#in_end_city').hide();
                    $('#out_end_city').show();
                }
            })
            Controller.api.bindevent();
        },
        edit: function () {
            var startCityType = $('#c-start_city_type').val()
            if(startCityType=="in"){
                $('#in_start_city').show();
                $('#out_start_city').hide();
            }else{
                $('#in_start_city').hide();
                $('#out_start_city').show();
            }
            $(document).on("click", "input[type=radio][name='row[starttype]']",
              function(){
                if($(this).val()=="in"){
                    $('#in_start_city').show();
                    $('#out_start_city').hide();
                }else{
                    $('#in_start_city').hide();
                    $('#out_start_city').show();
                }
            })
            var endCityType = $('#c-end_city_type').val()
            if(endCityType=="in"){
                $('#in_end_city').show();
                $('#out_end_city').hide();
            }else{
                $('#in_end_city').hide();
                $('#out_end_city').show();
            }
            $(document).on("click", "input[type=radio][name='row[endtype]']",
              function(){
                if($(this).val()=="in"){
                    $('#in_end_city').show();
                    $('#out_end_city').hide();
                }else{
                    $('#in_end_city').hide();
                    $('#out_end_city').show();
                }
            })
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
